package demo_State;

public class State_Test3 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 =new Thread(()->{
            //啥也不干让他处于运行状态
            for (long i = 0; i <10_0000_00000l ; i++) {
            }
        });
        Thread thread2 =new Thread(()->{
            try {
                thread1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //啥也不干让他处于运行状态好记录
            for (int i = 0; i <10_0000_0000 ; i++) {
            }
        });
        //启动线程之前记录一下线程状态
        System.out.println("thread1线程状态："+thread1.getState()+" TCB是否存活："+thread1.isAlive());
        System.out.println("thread2线程状态："+thread2.getState()+" TCB是否存活："+thread2.isAlive());
        System.out.println();
        thread1.start();
        thread2.start();
        //线程运行中记录线程状态
        Thread.sleep(1);//让打印线程慢一点防止抢占当前main线程抢占太快了
        System.out.println("thread1线程状态："+thread1.getState()+" TCB是否存活："+thread1.isAlive());
        System.out.println("thread2线程状态："+thread2.getState()+" TCB是否存活："+thread2.isAlive());
        System.out.println();
        //等待线程结束记录线程状态
        thread1.join();
        thread2.join();
        System.out.println("thread1线程状态："+thread1.getState()+" TCB是否存活："+thread1.isAlive());
        System.out.println("thread2线程状态："+thread2.getState()+" TCB是否存活："+thread2.isAlive());
        System.out.println();
    }
}
